#include "FrameTimer.h"
#include <sstream>
FrameTimer::FrameTimer() :
	m_timeCycles(0)
{
	LARGE_INTEGER cyclesPerSecond;
	QueryPerformanceFrequency(&cyclesPerSecond);
	m_cyclesPerSecond = cyclesPerSecond.QuadPart;
	LARGE_INTEGER startTimeCounter;
	QueryPerformanceCounter(&startTimeCounter);
	m_startTimeCounter = startTimeCounter.QuadPart;
}
FrameTimer::~FrameTimer()
{

}
void FrameTimer::Update()
{
	LARGE_INTEGER currentTimeCounter;
	QueryPerformanceCounter(&currentTimeCounter);
	long long currentTimeCycles = currentTimeCounter.QuadPart - m_startTimeCounter;
	m_deltaTimeCycles = currentTimeCycles - m_timeCycles;
	m_timeCycles = currentTimeCycles;
}
double FrameTimer::GetPredictedFrameTime()
{
	double result = CyclesToSeconds(m_deltaTimeCycles);
	if (result > (1.0f / 60.0f))//Less than 1 frame each second, then it must be a breakpoint
	{
		return (1.0f / 60.0f);
	}
	//debug,output fps
	std::ostringstream stringStream;
	stringStream << (1.0)/result << std::endl;
	OutputDebugString(stringStream.str().c_str());

	return result;
}